package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.model.User;
import org.apache.ibatis.annotations.*;

public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT COUNT(*) FROM user")
    int countUsers();

    @Select("SELECT * FROM user WHERE username = #{username} AND password = #{password}")
    User selectUserByUsernameAndPassword(@Param("username") String username, @Param("password") String password);

    @Insert("INSERT INTO user(id, username, password, employee_id, role_id, status, last_login, create_time, update_time, email) " +
            "VALUES(#{user.id},#{user.username},#{user.password},#{user.employeeId},#{user.roleId},#{user.status},#{user.lastLogin},#{user.createTime},#{user.updateTime},#{user.email})")
    void insertUser(@Param("user") User user);

    @Update("UPDATE user SET username = #{user.username}, password = #{user.password}, employee_id = #{user.employeeId}, role_id = #{user.roleId}, status = #{user.status}, last_login = #{user.lastLogin}, create_time = #{user.createTime}, update_time = #{user.updateTime}, email = #{user.email} WHERE id = #{user.id}")
    int updateById(@Param("user") User user);

    @Update("UPDATE user SET password = #{password} WHERE id = #{id}")
    int updatePasswordById(@Param("id") int id, @Param("password") String password);
}
